#define _CRT_SECURE_NO_WARNINGS 1

#include<stdio.h>
int Choose(int* Monkey,int n,int num)
{
	int numout = 0;
	int count = 0;
	int i = 0;
	do
	{
		for (int i = 0; i < n;i++)
		{
			if (Monkey[i] == i + 1)
			{
				count++;
				if (count%num == 0)
				{
					Monkey[i] = 0;
					numout++;
				}
			}
			if (numout == n - 1)
			{
				break;
			}
		}
	} while (numout < n - 1);
	for (int i = 0; i < n; i++)
	{
		if (Monkey[i] == i + 1)
		{
			return Monkey[i];
		}
	}
}
int main()
{
	int Monkey[1000] = { 0 };
	int n = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		Monkey[i] = i + 1;
	}
	int m = 3;
	int king = Choose(Monkey,n, m);
	printf("%d", king);

	return 0;
}